package com.jvyou.driver.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.jvyou.driver.auth.AuthenticationResult;
import com.jvyou.driver.auth.LoginRequest;
import com.jvyou.driver.auth.UserCredential;
import com.jvyou.driver.domain.modal.Result;
import com.jvyou.driver.service.AuthService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 橘柚
 * @since 2024/12/5 08:25
 */
@RestController
@RequestMapping("/auth")
@Slf4j
public class AuthController {

    @Resource
    private AuthService authService;

    @RequestMapping("/login")
    public Result<AuthenticationResult> doLogin(@LoginRequest UserCredential userCredential) {
        log.info("auth.login：{}", userCredential);
        return authService.doLogin(userCredential);
    }

    // 查询登录状态，浏览器访问： http://localhost:5421/user/isLogin
    @RequestMapping("isLogin")
    public String isLogin() {
        return "当前会话是否登录：" + StpUtil.isLogin();
    }

}
